<?php $this->load->view('common/admin_header');?>
<?php $this->load->view('common/kindeditor');?>
<link rel="stylesheet" type="text/css" href="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.css')?>" media="screen" />
<script type="text/javascript" src="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.pack.js')?>"></script>
<script type="text/javascript" src="<?=base_url('themes/admins/js/jscolor/jscolor.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#thumbnail").fancybox({
      helpers:{title:{type:'float'}}
  });
});
</script>
<div class="block withsidebar">
  <div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2><?=$lang['global_lable_36']?></h2>
    <ul>
      <li><a href="<?=site_url('admins/categorys').'?'.base64_decode($this->input->cookie('url_query'))?>"><?=$lang['global_lable_41']?></a></li>
    </ul>
  </div>
  <!-- .block_head ends -->
  <div class="block_content">
  <form id="form" name="form" action="<?=site_url('admins/categorys/modify')?>" method="post" enctype="multipart/form-data">
    <input type="hidden" name="edit_id" value="<?=set_value('edit_id',isset($edit_id)?$edit_id:'')?>" />
      <div class="sidebar">
        <ul class="sidemenu">
          <li><a href="#sb"><?=$lang['global_lable_33']?></a></li>
          <?php foreach($languages->result_array() as $k=>$lg):?>
          <li><a href="#sb<?=$lg['id']?>">
            <?=$lg['name']?>
            </a></li>
          <?php endforeach;?>
        </ul>
        <br/>
        <p>
          <input id="button1" class="btn btn-block btn-primary" type="submit" name="btn_save" value="<?=$lang['global_lable_12']?>" />
        </p>
        <p>
          <input id="button2" class="btn btn-block" type="reset" value="<?=$lang['global_lable_13']?>"/>
        </p>
      </div>
      <!-- .sidebar ends -->
      <div class="sidebar_content" id="sb">
      <?php $this->load->view('common/notify');?>
      <div class="sctitle"><i class="icon-pencil"></i> <?=$lang['global_lable_33']?></div>

      <?php $img_images=set_value('main_image',isset($main_image) && file_exists($main_image)?$main_image:'');?>
      <?php $show_image=!empty($img_images)?imagelib::resize_thumb($img_images,260,260):'themes/admins/img/no_image.png';?>
      <p>
          <a id="thumbnail" href="<?=base_url().(!empty($img_images)?$img_images:'themes/admins/img/no_image.png')?>" class="thumbnail">
              <img id="img_images" src="<?=base_url().$show_image?>" class="preview-img" style="max-width:300px">
          </a>
      </p>
      <p>
          <label><?=$lang['content_lable_36']?>*<e style="color:#e3302c">原图</e>:</label>
      <div id="simple-btn" data-tag="display_logo" class="btn btn-success js-fileapi-wrapper">
          <div class="js-browse">
              <input type="file" name="Filedata">
          </div>
          <div class="js-upload" style="display: none">
              <div class="progress progress-success">
                  <div class="js-progress bar"></div>
              </div>
              <span class="btn-txt">Uploading (<span class="js-size"></span>)</span>
          </div>
      </div>
      <input id="old_images" type="hidden" name="main_image" value="<?=set_value('main_image',isset($main_image) && file_exists($main_image)?$main_image:'')?>">
      <a href="#clear_img" tag="images" class="btn" style="display:<?=!empty($img_images)?'':'none'?>"><i class="icon-trash"></i> <?=$lang['content_lable_39']?></a>
      <br>
      </p>

      <?php $img_images=set_value('main_icon',isset($main_icon) && file_exists($main_icon)?$main_icon:'');?>
      <?php $show_image=!empty($img_images)?imagelib::resize_thumb($img_images,260,260):'themes/admins/img/no_image.png';?>
      <p>
          <a id="thumbnail2" href="<?=base_url().(!empty($img_images)?$img_images:'themes/admins/img/no_image.png')?>" class="thumbnail2">
              <img id="img2_imagesbtn" src="<?=base_url().$show_image?>" class="preview-img" style="max-width:300px">
          </a>
      </p>
      <p>
          <label><?=$lang['content_lable_36']?>*<e style="color:#e3302c">选图</e>:</label>
      <div id="simple-btn2" data-tag="display_logo" class="btn btn-success js-fileapi-wrapper">
          <div class="js-browse_btn">
              <input type="file" name="Filedata">
          </div>
          <div class="js-upload_btn" style="display: none">
              <div class="progress progress-success">
                  <div class="js-progress_btn bar"></div>
              </div>
              <span class="btn-txt">Uploading (<span class="js-size_btn"></span>)</span>
          </div>
      </div>
      <input id="old2_imagesbtn" type="hidden" name="main_icon" value="<?=set_value('main_icon',isset($main_icon) && file_exists($main_icon)?$main_icon:'')?>">
      <a href="#clear_img_btn" tag="imagesbtn" class="btn" style="display:<?=!empty($img_images)?'':'none'?>"><i class="icon-trash"></i> <?=$lang['content_lable_39']?></a>
      <br>
      </p>



      <p style="display:none">
        <label>自定義靜態網址:</label>
        <input type="text" class="text small" name="unique_url" value='<?=set_value('unique_url',isset($unique_url)?$unique_url:'')?>'/>
      </p>
      <p style="display:none">
         <label>父類別:</label>
         <select name="parent_id" id="parent_id">
          <option value="0" <?=set_select('parent_id','0')?> <?=isset($parent_id) && $parent_id==0?'selected':''?>>默認類型</option>
          <?php if(!empty($Categories)):?>
          <?php foreach($Categories as $row):?>
          <?php if($row['parent_id']==0&&$row['id']!=$edit_id): ?>
           <option value="<?=$row['id']?>" <?=set_select('parent_id',$row['id'])?> <?=isset($parent_id) && $parent_id==$row['id']?'selected':''?>><?=$row['title']?></option>
          <?php endif; ?>
          <?php endforeach;?>
          <?php endif;?>
          </select><span class="note required">*必填內容</span>
       </p>
       <p>
        <label><?=$lang['global_lable_17']?>:</label>
        <input type="text" class="text small" name="sort_order" value='<?=set_value('sort_order',isset($sort_order)?$sort_order:0)?>'/>
       </p>
       <p>
         <label><?=$lang['global_lable_16']?>:</label>
         <input type="radio" class="radio" name="status" value="1" <?=set_radio('status', '1', TRUE); ?> <?=isset($status) && $status==1?'checked':''?> />
         <span><?=$lang['global_lable_37']?></span>
         <input type="radio" class="radio" name="status" value="2" <?=set_radio('status', '2'); ?> <?=isset($status) && $status==2?'checked':''?> />
         <span><?=$lang['global_lable_38']?></span>
       </p>
      </div>
      <?php $lang_num=$languages->num_rows();?>
      <?php foreach($languages->result_array() as $lgs):?>
      <?php $k=$lgs['id'];?>
      <div class="sidebar_content" id="sb<?=$k?>">
        <?php if($lang_num>1):?>
        <div class="sctitle"><i class="icon-pencil"></i> <?=$lgs['name']?>&nbsp;&nbsp;<a href="javascript:void(0)" class="sync_lang" lang-num="<?=$lang_num?>" lang-id="<?=$k?>" title="<?=$lang['global_lable_44']?>"><?=$lang['global_lable_45']?></a></div>
        <?php else:?>
        <div class="sctitle"><i class="icon-pencil"></i> <?=$lgs['name']?></div>
        <?php endif;?>
      <p>
        <label><?=$lang['global_lable_15']?>:</label>
        <input type="text" value="<?=set_value('descriptions['.$k.'][title]',isset($descriptions[$k]['title'])?$descriptions[$k]['title']:'')?>" class="text small" name="descriptions[<?=$k?>][title]">
        <span class="note required">*<?=$lang['global_lable_35']?></span>
      </p>
      <p style="display:none">
        <label>內容簡介:</label>
        <textarea name="descriptions[<?=$k?>][introduction]"><?=set_value('descriptions['.$k.'][introduction]',isset($descriptions[$k]['introduction'])?$descriptions[$k]['introduction']:'')?></textarea>
      </p>
      <p style="display:none">
        <label>內容:</label>
        <textarea id="description<?=$k?>" class="details" name="descriptions[<?=$k?>][content]"><?=set_value('descriptions['.$k.'][content]',isset($descriptions[$k]['content'])?$descriptions[$k]['content']:'')?></textarea>
      </p>
      </div>
      <?php endforeach;?>
    </form>
  </div>
  <!-- .block_content ends -->
  <div class="bendl"></div>
  <div class="bendr"></div>
</div>
<!-- .block ends -->
<script type="text/javascript" charset="utf-8">
    window.FileAPI = {
        debug: true, // debug mode
        cors: false,    // if used CORS, set `true`
        media: false,   // if used WebCam, set `true`
        flashUrl:"<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.flash.swf')?>",
        staticPath:'themes/admins/js/jquery.fileapi/FileAPI/' // path to *.swf
    };
</script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.min.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.exif.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/jquery.fileapi.js')?>"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function($) {
        var folder=encodeURIComponent('uploads/adv_img/');
        $('#simple-btn').fileapi({
            url:"<?=site_url('admins/upload/single_upload')?>",
            data: {'folder':folder,'_size':'260x260','_element_id':'images','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
            multiple: false,
            accept: 'image/*',
            maxSize: 2 * FileAPI.MB,
            autoUpload: true,
            clearOnComplete:true,
            elements: {
                size: '.js-size',
                active: { show: '.js-upload', hide: '.js-browse' },
                progress: '.js-progress'
            },
            onComplete:function(evt,uiEvt){
                var error = uiEvt.error;
                var result = uiEvt.result; // server response
                if(!error && result){
                    // console.log(result);
                    if(result.error){
                        alert(result.error);
                        return;
                    }
                    $("#old_"+result.element_id).val(result.img_path);
                    $("#img_"+result.element_id).attr('src',result.thumb_img);
                    if ($('#thumbnail').length)
                        $("#thumbnail").attr('href',result.http_img);
                    if ($('a[href="#clear_img"]').length)
                        $('a[href="#clear_img"]').show();
                }
            }
        });

        //清除圖片
        $('a[href="#clear_img"]').click(function() {
            var obj=$(this);
            var action="<?=site_url('admins/upload/delete')?>";
            var defaule_img="<?=base_url('themes/admins/img/no_image.png')?>";
            clear_img(obj,action,defaule_img);
            return false;
        });


        $('#simple-btn2').fileapi({
            url:"<?=site_url('admins/upload/single_upload')?>",
            data: {'folder':folder,'_size':'260x260','_element_id':'imagesbtn','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
            multiple: false,
            accept: 'image/*',
            maxSize: 2 * FileAPI.MB,
            autoUpload: true,
            clearOnComplete:true,
            elements: {
                size: '.js-size_btn',
                active: { show: '.js-upload_btn', hide: '.js-browse_btn' },
                progress: '.js-progress_btn'
            },
            onComplete:function(evt,uiEvt){
                var error = uiEvt.error;
                var result = uiEvt.result; // server response
                if(!error && result){
                    // console.log(result);
                    if(result.error){
                        alert(result.error);
                        return;
                    }
                    $("#old2_"+result.element_id).val(result.img_path);
                    $("#img2_"+result.element_id).attr('src',result.thumb_img);
                    if ($('#thumbnail2').length)
                        $("#thumbnail2").attr('href',result.http_img);
                    if ($('a[href="#clear_img_btn"]').length)
                        $('a[href="#clear_img_btn"]').show();
                }
            }
        });

        //清除圖片
        $('a[href="#clear_img_btn"]').click(function() {
            var obj=$(this);
            var action="<?=site_url('admins/upload/delete')?>";
            var defaule_img="<?=base_url('themes/admins/img/no_image.png')?>";
            clear_img_btn(obj,action,defaule_img);
            return false;
        });
    });
</script>
<?php $this->load->view('common/admin_footer');?>